<?php
class Mwc_SystemPoint_SettingController extends Mage_Adminhtml_Controller_Action{
    public function indexAction(){
        $this->loadLayout()
            ->_addContent($this->getLayout()->createBlock('systempoint/setting'))
            ->renderLayout();
    }

    public function postAction(){
        if ($data = $this->getRequest()->getPost()){
            $tip = Mage::getModel('systempoint/setting')->setData($data);
            try{
                $tip->save();
                Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('systempoint')->__('Setting was successfully saved'));
                $this->getResponse()->setRedirect($this->getUrl('*/*/'));
                return;
            }
            catch (Exception $e){
                Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
            }
        }
        $this->getResponse()->setRedirect($this->getUrl('*/*/'));

        return;
    }

    public function editAction(){
        $this->loadLayout();
        $this->_addContent($this->getLayout()->createBlock('systempoint/setting_edit'));
        $this->renderLayout();
    }

    public function newAction(){
        $this->loadLayout()
            ->_addContent($this->getLayout()->createBlock('systempoint/expire_new'))
            ->renderLayout();
    }

    public function saveAction(){
        $id = $this->getRequest()->getParam('id', false);
        if ($data = $this->getRequest()->getPost()) {
            $setting = Mage::getModel('systempoint/setting')->load($id)->addData($data);
            try {
                $setting->setId($id)->save();
                print_r($setting);
                Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('systempoint')->__('Setting successfully updated'));
                $this->getResponse()->setRedirect($this->getUrl('*/*/'));
                return;
            }
            catch (Exception $e){
                Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
            }
        }
        $this->_redirectReferer();
    }
}